using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class QQMailMessageItem : BaseChatElement
	{
		private const string TAG = "QQMailMessageItem";
		private Button ContentButton;
		private MenuItem ContentMenuItem;
		private QQMail mMailInfo;
		public static DependencyProperty AttatchProperty = DependencyProperty.Register("AttatchSource", typeof(ImageSource), typeof(QQMailMessageItem), new PropertyMetadata(new ImageSourceConverter().ConvertFromString(R.theme.Plugin_qqMail_attatch) as ImageSource, new PropertyChangedCallback(QQMailMessageItem.OnAttatchChanged)));
		public static DependencyProperty WaterImgProperty = DependencyProperty.Register("WaterSource", typeof(ImageSource), typeof(QQMailMessageItem), new PropertyMetadata(new ImageSourceConverter().ConvertFromString(R.theme.Plugin_qqMail_water_bk) as ImageSource, new PropertyChangedCallback(QQMailMessageItem.OnWaterImgChanged)));
		public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(QQMailMessageItem), new PropertyMetadata(strings.Con_FMsg_TxtName, new PropertyChangedCallback(QQMailMessageItem.OnTitleChanged)));
		public static DependencyProperty FromNameProperty = DependencyProperty.Register("FromName", typeof(string), typeof(QQMailMessageItem), new PropertyMetadata(strings.Con_FMsg_TxtName, new PropertyChangedCallback(QQMailMessageItem.OnFromNameChanged)));
		public static DependencyProperty DescriptProperty = DependencyProperty.Register("Descript", typeof(string), typeof(QQMailMessageItem), new PropertyMetadata(strings.Con_FMsg_TxtName, new PropertyChangedCallback(QQMailMessageItem.OnDescriptChanged)));
		public static DependencyProperty TimeTxtProperty = DependencyProperty.Register("TimeTxt", typeof(string), typeof(QQMailMessageItem), new PropertyMetadata(strings.Con_FMsg_TxtName, new PropertyChangedCallback(QQMailMessageItem.OnTimeTxtChanged)));
		private bool _contentLoaded;
		public ImageSource Attatch
		{
			get
			{
				return (ImageSource)base.GetValue(QQMailMessageItem.AttatchProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.AttatchProperty, value);
			}
		}
		public ImageSource WaterImg
		{
			get
			{
				return (ImageSource)base.GetValue(QQMailMessageItem.WaterImgProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.WaterImgProperty, value);
			}
		}
		public string Title
		{
			get
			{
				return (string)base.GetValue(QQMailMessageItem.TitleProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.TitleProperty, value);
			}
		}
		public string FromName
		{
			get
			{
				return (string)base.GetValue(QQMailMessageItem.FromNameProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.FromNameProperty, value);
			}
		}
		public string Descript
		{
			get
			{
				return (string)base.GetValue(QQMailMessageItem.DescriptProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.DescriptProperty, value);
			}
		}
		public string TimeTxt
		{
			get
			{
				return (string)base.GetValue(QQMailMessageItem.TimeTxtProperty);
			}
			set
			{
				base.SetValue(QQMailMessageItem.TimeTxtProperty, value);
			}
		}
		public QQMailMessageItem()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.QQMailMessageItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.QQMailMessageItem_Unloaded));
		}
		private void QQMailMessageItem_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void QQMailMessageItem_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.ContentButton = (base.GetTemplateChild("ContentButton") as Button);
			this.ContentMenuItem = (base.GetTemplateChild("DeleteMsgMenu") as MenuItem);
			this.ContentButton.SetValue(MMTiltEffect.IsTiltEnabledProperty, true);
			this.ContentButton.add_Click(new RoutedEventHandler(this.ContentButton_Click));
			this.ContentMenuItem.Click += new RoutedEventHandler(this.ContentMenuItem_Click);
		}
		private void ContentButton_Click(object sender, RoutedEventArgs e)
		{
			if (this.mclickEvent != null)
			{
				this.mclickEvent(this.chatMsg_0, this);
			}
			if (this.chatMsg_0 == null)
			{
				return;
			}
			QQMail qQMail = QQMailMgr.convertChatMsg2QQMail(this.chatMsg_0);
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/QQMail/UI/QQMailDetailInfoView.xaml", new object[]
			{
				qQMail
			}, false);
		}
		private void ContentMenuItem_Click(object sender, RoutedEventArgs e)
		{
			if (this.chatMsg_0 == null)
			{
				return;
			}
			if (this.chatMsg_0 is ChatTimeMsg)
			{
				return;
			}
			ChatMsgMgr.deleteTalkMsg(this.chatMsg_0);
		}
		private void RefreshItem(ChatMsg chatMsg_1)
		{
			if (chatMsg_1 == null)
			{
				return;
			}
			this.mMailInfo = QQMailMgr.parseMailXml(chatMsg_1.strMsg);
			if (this.mMailInfo == null)
			{
				return;
			}
			if (this.mMailInfo.hasAttach)
			{
				Log.smethod_5("QQMailMessageItem", "mail " + this.mMailInfo.strTitle + "has Attach");
			}
			else
			{
				Log.smethod_5("QQMailMessageItem", "mail " + this.mMailInfo.strTitle + "hasn't Attach");
				this.Attatch = null;
			}
			this.Title = this.mMailInfo.strTitle;
			if (this.mMailInfo.strTitle.get_Length() > 30 && this.chinaTxtCount(this.mMailInfo.strTitle) > 30)
			{
				string text = this.mMailInfo.strTitle.Substring(0, this.mMailInfo.strTitle.get_Length() - 2);
				this.Title = text + "...";
			}
			this.FromName = this.mMailInfo.strSender;
			this.Descript = this.mMailInfo.strDescipt;
			this.TimeTxt = Util.formatTimeInChatMsg(chatMsg_1.nCreateTime);
		}
		public int chinaTxtCount(string strTxt)
		{
			int num = 0;
			if (string.IsNullOrEmpty(strTxt))
			{
				return num;
			}
			int num2 = Convert.ToInt32("4e00", 16);
			int num3 = Convert.ToInt32("9fff", 16);
			for (int i = 0; i < strTxt.get_Length(); i++)
			{
				int num4 = Convert.ToInt32(Convert.ToChar(strTxt.Substring(i, 1)));
				if (num4 >= num2 && num4 <= num3)
				{
					num++;
				}
			}
			if (strTxt.get_Length() > num)
			{
				int num5 = strTxt.get_Length() - num;
				int num6 = num5 / 2;
				int num7 = num5 % 2;
				if (num7 > 0)
				{
					num6++;
				}
				num += num6;
			}
			return num;
		}
		public void ItemClickHandle(ChatMsg chatMsg_1)
		{
			if (chatMsg_1 == null)
			{
				return;
			}
			if (this.mMailInfo == null)
			{
				return;
			}
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			if (this.mMailInfo != null)
			{
				if (this.mMailInfo == null)
				{
					return;
				}
			}
			else
			{
				if (this.mMailInfo != null && this.mMailInfo == null)
				{
					return;
				}
			}
		}
		public override void SetChatMsg(ChatMsg Msg)
		{
			base.SetChatMsg(Msg);
			this.RefreshItem(Msg);
		}
		private static void OnAttatchChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnWaterImgChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnTitleChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnFromNameChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnDescriptChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnTimeTxtChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/QQMail/UI/QQMailMessageItem.xaml", 2));
		}
	}
}
